package code.ws_common_interface.ui.alert
{
	import code.ws_common_interface.base.IUi;
	import code.ws_common_utils.SysUtils;
	
	import feathers.controls.Button;
	import feathers.controls.ImageLoader;
	import feathers.controls.text.TextFieldTextRenderer;
	import feathers.core.ITextRenderer;
	
	import feathers_exd.ctrls.ULabel;
	
	import flash.text.TextFormat;
	
	import starling.display.Quad;
	import starling.display.Sprite;

	/**
	 * 安卓系统推出应用程序确认面板 
	 * @author Jonathan.Qiang
	 * 
	 */	
	public class AndriodAppAlert extends Sprite implements IUi
	{
		private var quad:Quad;
		private var confirmBg:Quad;
		private var confirmBg_up:Quad;
		private var line:Quad;
		private var icon:ImageLoader;
		private var title:ULabel;
		private var info:ULabel;
		public var okBtn:Button;
		public var cancelBtn:Button;
		
		/**
		 * 构造函数 
		 */		
		public function AndriodAppAlert()
		{
			ini();
		}
		
		/**
		 * 初始化 
		 * 
		 */		
		public function ini():void
		{
			quad = new Quad( SysUtils.stage.stageWidth, SysUtils.stage.stageHeight, 0x000000 );
			quad.alpha = 0.5;
			addChild( quad );
			
			// 确认框背景
			confirmBg = new Quad( 800, 440, 0x929293 );
			addChild( confirmBg );
			confirmBg.x = int( this.width - confirmBg.width ) * .5;
			confirmBg.y = int( this.height - confirmBg.height ) * .5;
			
			// 确认框背景上层
			confirmBg_up = new Quad( 796, 340, 0x14202e );
			addChild( confirmBg_up );
			confirmBg_up.x = confirmBg.x + 2;
			confirmBg_up.y = confirmBg.y + 2;
			
			// line
			line = new Quad( 796, 1, 0x25405e );
			addChild( line );
			line.x = confirmBg_up.x;
			line.y = confirmBg_up.y + 200;
			
			// logo图
			icon = new ImageLoader();
			icon.source = "assets/res/icon/128png.png";
			addChild( icon );
			icon.x = confirmBg_up.x + 30;
			icon.y = confirmBg_up.y + 30;
			
			var t:TextFormat = new TextFormat( "_sans", 12, 0xffffff, true );
			
			// 标题
			title = new ULabel( "Immortal", t );
			title.changeSize( 40 );
			addChild( title );
			title.x = confirmBg_up.x + 180;
			title.y = confirmBg_up.y + 110;
			
			// 信息
			t.size = 30;
			t.bold = false;
			info = new ULabel( "Are you sure you want to quit it ?", t );
			addChild( info );
			info.x = confirmBg_up.x + 10;
			info.y = line.y + 25;
			
			// 确认、取消按钮
			var btn_t:TextFormat = new TextFormat( "_sans", 40, 0x000000, true );
			var btn_dt:TextFormat = new TextFormat( "_sans", 40, 0xffffff, true );
			okBtn = new Button();
			okBtn.defaultSkin = new Quad( 390, 85, 0xffffff );
			okBtn.downSkin = new Quad( 390, 85, 0x333333 );
			okBtn.labelFactory =  function():ITextRenderer{ return new TextFieldTextRenderer() };
			okBtn.defaultLabelProperties.textFormat = btn_t;
			okBtn.downLabelProperties.textFormat = btn_dt;
			okBtn.label = "confirm";
			addChild( okBtn );
			okBtn.x = confirmBg_up.x + 4;
			okBtn.y = confirmBg_up.y + confirmBg_up.height + 5;
			
			cancelBtn = new Button();
			cancelBtn.defaultSkin = new Quad( 390, 85, 0xffffff );
			cancelBtn.downSkin = new Quad( 390, 85, 0x666666 );
			cancelBtn.labelFactory =  function():ITextRenderer{ return new TextFieldTextRenderer() };
			cancelBtn.defaultLabelProperties.textFormat = btn_t;
			cancelBtn.downLabelProperties.textFormat = btn_dt;
			cancelBtn.label = "cancel";
			addChild( cancelBtn );
			cancelBtn.x = 645;
			cancelBtn.y = okBtn.y;
			
			t = null;
			btn_t = null;
		}
		
		
		/**
		 * 释放 
		 * 
		 */		
		public function kill():void
		{
			if( icon )
			{
				icon.dispose();
			}
			this.dispose();
		}
	}
}